package com.lxy.demo.controller;

import com.github.pagehelper.PageInfo;
import com.lxy.demo.service.BookInfoService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Component
@RequestMapping("book")
public class BookInfoController {

    @Autowired
    private BookInfoService bookInfoService;

    @RequestMapping("main")
    public String main(Integer bookType,String bookName,String isBorrow,
                        @RequestParam(required = false,defaultValue = "1") Integer pageNum,
                       Model model){
        PageInfo book = bookInfoService.findBook(pageNum, bookType, bookName, isBorrow);
        model.addAttribute("book",book);
        model.addAttribute("bookName",bookName);
        model.addAttribute("isBorrow",isBorrow);
        model.addAttribute("bookType",bookType);
        book.getList().forEach(System.out::println);
        return "main";
    }
}
